package com.lc.channel;

import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.channels.FileChannel;

import org.junit.Test;

/**
 * @author 逝兮诚
 * @date 2017年6月22日 下午2:56:27
 * @see 如果有一个channel是FileChannel，可以将channel的数据直接传送到另一个通道。
 */
public class ChannelTransferTest {

	@SuppressWarnings("resource")
	@Test
	public void transferTo() throws IOException {
		RandomAccessFile fromfile = new RandomAccessFile("src/main/resources/fromFile.txt", "r");
		FileChannel fromChannel = fromfile.getChannel();
		
		RandomAccessFile tofile = new RandomAccessFile("src/main/resources/toFile.txt", "rw");
		FileChannel toChannel = tofile.getChannel();
		
		fromChannel.transferTo(0, fromChannel.size(), toChannel);
	}

}
